<template>
	<view>
		<van-sticky offset-top="0">
			<van-search :value="keywords" placeholder="请输入搜索关键词" />
			<van-tabs :active="active" @change="onChangeTab">
				<van-tab :title="item.name " v-for="(item,index) in tabList" :key="index"></van-tab>
			</van-tabs>
		</van-sticky>

		<view class="noticeListBox">
			<view v-for="(item,index) in noticeList" :key="index" class="noticeItem" @click="routeTo(item)">
				<view class="title">
					{{ item.noticeType }}
				</view>
				<view class="content">
					<view class="contentBox">{{ item.title }}</view>
				</view>
				<view v-if="item.isRead=='N'" class="status" style="color:#2daa14">未读 </view>
				<view class="status" style="color:#ff0000" v-else>已读 </view>
			</view>
		</view>
	</view>
</template>
<script setup>  
	import {
		dailyNoticePage,
	} from "@/api"
	import {
		onLoad,
		onReachBottom
	} from '@dcloudio/uni-app';
   import { USER_INFO_KEY } from "@/enums/cacheEnum"
	const useDict = useDictStore();
	const NOTICE_TYPE=useDict.getData("NOTICE_TYPE"); 
	const CommonYesNoEnum=useDict.getData("CommonYesNoEnum"); 
    const userInfo = ref(cache.get(USER_INFO_KEY))
	console.log(CommonYesNoEnum)
	const keywords = ref('')
	const active = ref(0)
	const tabList = ref([{
			name: '全部', 
		},
		{
			name: '未读', 
		},
		{
			name: '已读', 
		},
	])
	const noticeList = ref([])
	const onChangeTab = (e) => {
        console.log(e)
		active.value=e
		pageData.value.page=1;
		noticeList.value=[] 
		getlist()
	}
	onLoad(()=>{
		getlist()
	})
	const pageData=ref({
		page:1,
		size:15
	})
	const pages=ref(0)
	const getlist = () => {
	    let obj={
			current:pageData.value.page,
			size:pageData.value.size,
			createTime_desc:'createTime_desc',
			yard_id:userInfo.value.yardId
		}
		if(active.value==1){
			obj.isRead='N'
		}
		if(active.value==2){
			obj.isRead='Y'
		}
		dailyNoticePage(obj).then(res=>{
			pages.value=res.data.pages
			res.data.current==1?noticeList.value=res.data.records:noticeList.value=noticeList.value.concat(res.data.records)
		})
	}
	
	 
    onReachBottom(()=>{
		if(pageData.value.page<pages.value){
			pageData.value.page++
			getlist()
		}
	})
	const routeTo = (item) => {
		uni.navigateTo({
			url: '/pages/notice/detail?id=' + item.id,
		})
	}
</script>
<style lang="scss" scoped>
	.noticeListBox {
		padding: 20rpx 30rpx;
	}

	.noticeItem {
		display: flex;
		align-items: center;
		padding: 20rpx 30rpx;
		background: #fff;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		font-size: 28rpx;

		.title {
			width: 60rpx;
			height: 60rpx;
			border-radius: 50%;
			text-align: center;
			line-height: 60rpx;
			background: rgb(51, 127, 228);
			margin-right: 20rpx;
			color: #fff;
		}

		.content {
			flex: 1;
			font-size: 28rpx;

			.contentBox {
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				width: 460rpx;
			}
		}
	}
</style>